package com.fortune.service.impl;

import com.faneui.common.exception.BusinessException;
import com.fortune.dal.dao.CardDAO;
import com.fortune.dal.model.Card;
import com.fortune.service.CardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardServiceImpl implements CardService {

    @Autowired
    private CardDAO cardDAO ;

    @Override
    public void addCard(Card card) throws BusinessException {
        try{
            cardDAO.insert(card);
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyCard(Card card) throws BusinessException {
        try{
            cardDAO.updateById(card) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public Card queryCard(Integer cardId) throws BusinessException {
        Card c = null;
        try{
            c = cardDAO.queryById(cardId) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return c;
    }

    @Override
    public List<Card> queryCardList(Card card) throws BusinessException {
        List<Card> list = null;
        try{
            list = cardDAO.queryByModel(card) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return list;
    }

    @Override
    public List<Card> queryCardListByCustId(Integer custId) throws BusinessException {
        Card param = new Card();
        param.setCustId(custId);
        return queryCardList(param);
    }
}
